$(document).ready(function()
{
    $(document).on("click",".seniorMenu",function(){
        $(".seniorMenu").css('background','#FFF');
        $(".seniorMenu").css('color','#F00');
        $(this).css('background','#F00');
        $(this).css('color','#FFF');
        seniorMenuEnter = $(this);
        $.post("./seniorMenu",{data:$(this).attr('data')},function(data){
            var s='';
            for(var i=0;i<data.length;i++){
                s +='<div class="minorMenu" data="'+data[i]['data']+'"><span>'+data[i]['name']+'</span></div>';
            }
            $("#menuBox").html(s);
            $("#content").hide();
        },
        'json'
        );
    });
    var seniorMenuEnter = 0;
    $(document).on("mouseenter",".seniorMenu",function(){
        $(".seniorMenu").css('background','#FFF');
        $(".seniorMenu").css('color','#F00');
        $(this).css('background','rgb(244,125,132)');
        $(this).css('color','#FFF');
    });
    $(document).on("mouseleave",".seniorMenu",function(){
        $(".seniorMenu").css('background','#FFF');
        $(".seniorMenu").css('color','#F00');
        if(seniorMenuEnter!=0){
            $(".seniorMenu").css('background','#FFF');
            $(".seniorMenu").css('color','#F00');
            seniorMenuEnter.css('background','#F00');
            seniorMenuEnter.css('color','#FFF');
        }
    });

    $(document).on("click",".minorMenu span",function(){
        $(".minorMenu span").css('background','#FFF');
        $(this).css('background','rgb(107,205,253)');
        minorMenuEnter = $(this);
        $("#content").attr('src','./minorMenu/'+$(this).parent().attr('data'));
        $("#content").show();
    });
    $(document).on("mouseenter",".minorMenu span",function(){
        $(".minorMenu span").css('background','#FFF');
        $(this).css('background','rgb(180,230,254)');
    });
    $(document).on("mouseleave",".minorMenu span",function(){
        $(".minorMenu span").css('background','#FFF');
        if(minorMenuEnter!=0){
            $(".minorMenu span").css('background','#FFF');
            minorMenuEnter.css('background','rgb(107,205,253)');
        }
    });

    $("#dialog").dialog({autoOpen: false});

    $('#logout').click(function(){
        $.post('./logout');
        setTimeout(function(){location = location;},200);
    });

    $.post("/admin/Menu",{},function(data){
            var s='';
            for(var i=0;i<data.length;i++){
                s += '<div class="seniorMenu" data="'+data[i]['data']+'"><span>'+data[i]['name']+'</span></div>';
            }
            $("#leftmenu").html(s);
        },'json'
    );

});

function message(mess,width,height){
    var width = width ? width : 200;
    var height = height ? height : 153;
    $("#dialog").text(mess);
    $("#dialog").dialog({
        autoOpen: false,
        resizable: false,
        title:'消息',
        width:width,
        height:height,
        modal: true,
        buttons: {
            '确定': function() {
                $(this).dialog('close');
            }
        }
    });
    $("#dialog").dialog('open');
};

function confirm(mess,func,width,height){
    var width = width ? width : 200;
    var height = height ? height : 153;
    $("#dialog").text(mess);
    $("#dialog").dialog({
        autoOpen: false,
        resizable: false,
        title:'消息',
        width:width,
        height:height,
        modal: true,
        buttons: {
            '确定': func,
            '取消': function() {
                $(this).dialog('close');
            }
        }
    });
    $("#dialog").dialog('open');
};

function SetCwinHeight(obj)
{
    var cwin=obj;
    if (document.getElementById)
    {
        if (cwin && !window.opera)
        {
            if (cwin.contentDocument && cwin.contentDocument.body.offsetHeight)
                cwin.height = cwin.contentDocument.body.offsetHeight + 20; //FF NS
            else
                if(cwin.Document && cwin.Document.body.scrollHeight)
                    cwin.height = cwin.Document.body.scrollHeight + 10;//IE
        }
        else
        {
            if(cwin.contentWindow.document && cwin.contentWindow.document.body.scrollHeight)
                cwin.height = cwin.contentWindow.document.body.scrollHeight;//Opera
        }
    }
};

var minorMenuEnter = 0;
function jump(src,ident){
    $('#content').attr('src','./minorMenu/'+src);
    $(".minorMenu span").css('background','#FFF');
    minorMenuEnter = $(".minorMenu[data='"+src+"']").find('span');
    minorMenuEnter.css('background','rgb(107,205,253)');
    setTimeout(function(){
        $('#content').contents().find('.search input').val(ident);
        $('#content').contents().find('.search button').click();
    },300);
};
